using System;
using System.Collections.Generic;
using System.Text;
using Wrath.Xml;
using System.ComponentModel;

using Wrath.RuleForge.Interfaces;

namespace Wrath.RuleForge.Property
{
    public class IncludeFileWrapper : IPropertyWrapper<Element>
    {
        private bool hasChanged;
        private Element element;

        private Wrath.Xml.Attribute sourceAttribute;

        [Category("IncludeFile")]
        [Description("The filename of the xml file to include.")]
        public string Source
        {
            get
            {
                if (sourceAttribute != null)
                {
                    return sourceAttribute.Value;
                }

                return "";
            }
            set
            {
                if (sourceAttribute == null)
                {
                    sourceAttribute = new Wrath.Xml.Attribute();
                    sourceAttribute.Name = "source";
                    element.Attributes.Add(sourceAttribute);
                }

                sourceAttribute.Value = value;
            }
        }

        public IncludeFileWrapper(Element element)
        {
            this.element = element;
            sourceAttribute = element.FindAttribute("source");
        }

        #region IPropertyWrapper<Element> Members

        [Browsable(false)]
        public bool HasChanged
        {
            get
            {
                return hasChanged;
            }
            set
            {
                hasChanged = value;
            }
        }

        [Browsable(false)]
        public Element Data
        {
            get { return element; }
        }

        #endregion
    }
}
